const mongoose = require('mongoose');

const inboundOrderSchema = new mongoose.Schema({
  productId: { 
    type: mongoose.Schema.Types.ObjectId, 
    ref: 'Product', 
    required: true 
  },
  productName: { type: String, required: true },
  inboundTime: { type: Date, required: true, default: Date.now },
  quantity: { type: Number, required: true, min: 1 },
  supplier: { type: String, required: true },
  status: { 
    type: String, 
    enum: ['待审核', '待入库', '已入库', '审核不通过', '完成', '入库失败'],  // 新增"入库失败"状态
    default: '待审核' 
  },
  // 新增：关联的采购订单ID
  purchaseOrderId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'PurchaseOrder',
    // Remove "required: true" if optional
  }
}, { timestamps: true });

module.exports = mongoose.model('InboundOrder', inboundOrderSchema);